package flc.ast.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ToastUtils;

import flc.ast.R;
import flc.ast.databinding.DialogRenameStyleBinding;
import stark.common.basic.base.BaseSmartDialog;

public class RenameDialog extends BaseSmartDialog<DialogRenameStyleBinding> implements View.OnClickListener {
    public String title;
    public String hint;

    public RenameDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_rename_style;
    }

    @Override
    protected void initView(View view) {
        mDataBinding.tvTitle.setText(title);
        mDataBinding.etName.setHint(hint);
        mDataBinding.ivCancel.setOnClickListener(this);
        mDataBinding.ivConfirm.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ivCancel:
                dismiss();
                break;
            case R.id.ivConfirm:
                dismiss();
                if (!TextUtils.isEmpty(mDataBinding.etName.getText().toString().trim())) {
                    if (listener != null) {
                        listener.clickRename(mDataBinding.etName.getText().toString());
                    }
                } else {
                    ToastUtils.showShort(R.string.please_input_name_hint);
                }
                break;
            default:
                break;
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickRename(String name);
    }
}
